# import pytest

import requests


# @pytest.fixture(scope='module')  #@pytest.fixture装饰器整个模块运行前运行一次里面调用的方法
def health_login():
    '''
    获取token并返回
    :return:返回headers
    '''
    unionId='oi5tWwl3O1K6_johy9hECcCQlUx4'  #
    url='https://uchos-test.perfect99.com/mini/login'
    data={"unionId":unionId,"loginType":"go"}
    hearder={'client':'miniapp','Content-Type':'application/json','GW-Client':'test'}
    resp=requests.post(url=url,headers=hearder,json=data)
    token=str('Bearer '+resp.json()['data']['accessToken'])
    #这个函数得到token
    # ACCESSTOKEN = 'Bearer ' + token
    # HEADERS = {'Authorization': ACCESSTOKEN, 'content_type': 'Application/json'}
    return token

def cardLogin():
    url="https://uc-test.perfect99.com/api/login/oauth/token"
    headers={'Content-Type':'application/x-www-form-urlencoded',
             'Authorization': 'Basic cG9ydGFsX2FwcDpwZXJmZWN0X3BvcnRhbA==',
             'GW-Client':'test'}
    data={
        'username':3000001762,
        'password':888888,
        'grant_type':'password',
        'auth_type':'shortcut',   #这是后面接口改动，必须短信验证，加的参数，压测需要绕开
        'phoneNo':13687314011
    }
    resp=requests.post(url,data=data,headers=headers)
    print(resp.content)
    print(resp.json()['data']['access_token'])
    Token=str('bearer '+resp.json()['data']['access_token'])
    '''
    TODO:商城前端的认证是‘bearer ’开头的
    '''
    return Token

def userinfo():
    url='https://uc-test.perfect99.com/api/mobile/personalInfo/getCurrentUserInfo'
    headers={'Authorization':cardLogin(),'content_type':'Application/json'}
    resp=requests.get(url,headers=headers)
    return resp.content

print(cardLogin())
# print(userinfo())